package com.molichuxing.services.infrastructure.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.molichuxing.services.infrastructure.bean.MessageTemplateBean;
import com.molichuxing.services.infrastructure.convertor.Convert;
import com.molichuxing.services.infrastructure.dao.MessageTemplateMapper;
import com.molichuxing.services.infrastructure.dto.response.MessageTemplateDto;
import com.molichuxing.services.infrastructure.service.MessageTemplateService;

/**
 * <p>
 * 消息推送 服务实现类
 * </p>
 *
 * @author 
 * @since 2019-08-14
 */
@Service("messageTemplateService")
public class MessageTemplateServiceImpl implements MessageTemplateService {

  @Resource
  private MessageTemplateMapper messageTemplateMapper;


  @Override
  public MessageTemplateDto getByKey(String key) {
    return Convert.toMessageTemplateDto(messageTemplateMapper.getByKey(key));
  }
  
  @Override
  public Map<String, MessageTemplateDto> getByKey(List<String> keys) {
	  if(null == keys || keys.isEmpty()) {
		  return null;
	  }
	 List<MessageTemplateBean> list= messageTemplateMapper.getByKeys(keys);
	 List<MessageTemplateDto> dtoList = Convert.toMessageTemplateDto(list);
	 if(null == dtoList || dtoList.isEmpty()) {
		 return null;
	 }
	 Map<String, MessageTemplateDto> map =new HashMap<>(dtoList.size());
	 for (MessageTemplateDto dto : dtoList) {
		map.put(dto.getKey(), dto);
	 }
     return map;
  }
}
